﻿

Public Class xtf_ABMsoldadura_
    Dim dtt_linea_ As New DataTable
    Dim dtt_isometrico_ As New DataTable
    Dim dtt_soldadura_ As New DataTable

    Dim PERMISONuevoLinea As String = "001064003"
    Dim PERMISOModificarLinea As String = "001064004"
    Dim PERMISONuevoisometrico As String = "001065002"
    Dim PERMISOModificarisometrico As String = "001065003"
    Dim PERMISONuevosoldadura As String = "001051002"
    Dim PERMISOModificarsoldadura As String = "001051003"

    Public obj_obra As cls_centrocostoorden_

    Public Sub New(ByVal obra As cls_centrocostoorden_)

        ' This call is required by the designer.
        InitializeComponent()
        obj_obra = obra
        txt_codigo.Text = obra.codigo
        txt_nombre.Text = obra.nombrecorto
        If Not IsNothing(obra.cliente) Then
            txt_cliente.Text = obra.cliente.ToString
        Else
            txt_cliente.Text = "Sin Asignar."
        End If

        Me.Text = "Soldaduras - " & obra.ToString

        'Prepara grid y datasource linea----------------------------------------------------
        dtt_linea_.Columns.Add("idlinea", GetType(Integer))
        dtt_linea_.Columns.Add("Objeto", GetType(Object))
        dtt_linea_.Columns.Add("Nombre", GetType(String))
        dtt_linea_.Columns.Add("Alcance", GetType(Integer))
        dtt_linea_.Columns.Add("Sistema", GetType(String))
        dtt_linea_.Columns.Add("Sub Sistema", GetType(String))
        dtt_linea_.Columns.Add("Material", GetType(String))

        gdc_linea_.DataSource = dtt_linea_
        gdc_linea_.ForceInitialize()

        gdv_linea_.PopulateColumns()
        gdv_linea_.Columns("Objeto").Visible = False
        gdv_linea_.Columns("idlinea").Caption = "Identificador (ID)"
        '-----------------------------------------------------------------------------------------------

        'Prepara grid y datasource isometrico----------------------------------------------------
        dtt_isometrico_.Columns.Add("idisometrico", GetType(Integer))
        dtt_isometrico_.Columns.Add("Objeto", GetType(Object))
        dtt_isometrico_.Columns.Add("Nombre", GetType(String))
        dtt_isometrico_.Columns.Add("Código", GetType(String))
        dtt_isometrico_.Columns.Add("Plano", GetType(String))
        dtt_isometrico_.Columns.Add("Area", GetType(String))
        dtt_isometrico_.Columns.Add("Skid", GetType(String))
        dtt_isometrico_.Columns.Add("Contratista", GetType(String))
        dtt_isometrico_.Columns.Add("Kilos campo", GetType(Decimal))
        dtt_isometrico_.Columns.Add("Kilos taller", GetType(Decimal))
        dtt_isometrico_.Columns.Add("Observaciones", GetType(String))
        dtt_isometrico_.Columns.Add("Linea opcional 1", GetType(String))
        dtt_isometrico_.Columns.Add("Linea opcional 2", GetType(String))
        dtt_isometrico_.Columns.Add("Hojas", GetType(Integer))
        dtt_isometrico_.Columns.Add("Hojas Total", GetType(Integer))

        gdc_isometrico_.DataSource = dtt_isometrico_
        gdc_isometrico_.ForceInitialize()

        gdv_isometrico_.PopulateColumns()
        gdv_isometrico_.Columns("Objeto").Visible = False
        gdv_isometrico_.Columns("idisometrico").Caption = "Identificador (ID)"
        '-----------------------------------------------------------------------------------------------


        'Prepara grid y datasource soldadura----------------------------------------------------
        dtt_soldadura_.Columns.Add("idsoldadura", GetType(Integer))
        dtt_soldadura_.Columns.Add("Objeto", GetType(Object))
        dtt_soldadura_.Columns.Add("Tipo", GetType(String))
        dtt_soldadura_.Columns.Add("Código", GetType(String))
        dtt_soldadura_.Columns.Add("Diámetro Nom.", GetType(Decimal))
        dtt_soldadura_.Columns.Add("Diámetro", GetType(Decimal))
        dtt_soldadura_.Columns.Add("Schedule", GetType(String))
        dtt_soldadura_.Columns.Add("Espesor", GetType(Decimal))
        dtt_soldadura_.Columns.Add("Tipo de Soldadura", GetType(String))
        dtt_soldadura_.Columns.Add("Se hace en", GetType(String))
        dtt_soldadura_.Columns.Add("Tipo Nuevo", GetType(String))

        gdc_soldadura_.DataSource = dtt_soldadura_
        gdc_soldadura_.ForceInitialize()

        gdv_soldadura_.PopulateColumns()
        gdv_soldadura_.Columns("Objeto").Visible = False
        gdv_soldadura_.Columns("idsoldadura").Caption = "Identificador (ID)"
        '-----------------------------------------------------------------------------------------------
        opt_soldaduratipo.SelectedIndex = 2
        cargarLinea_(obra.idcentrocostoorden)
        FiltrarColumnas(gdv_isometrico_)
        PerzonalizarControl(gdc_isometrico_)
        FiltrarColumnas(gdv_linea_)
        PerzonalizarControl(gdc_linea_)
        FiltrarColumnas(gdv_soldadura_)
        PerzonalizarControl(gdc_soldadura_)
        ' Add any initialization after the InitializeComponent() call.

    End Sub

#Region "Linea"
    Public Overridable Sub bbi_NuevoLinea_ItemClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsb_lineaNuevo.Click
        If ComprobarPermiso(PERMISONuevoLinea) Then
            Dim ABM As New xtf_ABMlinea(obj_obra)
            ABM.Nuevo(Me)
            ABM.ControlarModificaciones(ABM.lac_general.Items)
        End If
        Strings.Left(Replace(Me.Name, "xtf_LISTADO", "xtf_ABM"), Replace(Me.Name, "xtf_LISTADO", "xtf_ABM").Length - 2)
    End Sub

    Public Overridable Sub bbi_ModificarLinea_ItemClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsb_lineaModificar.Click
        If ComprobarPermiso(PERMISOModificarLinea) Then
            Try
                Dim barrio As New cls_linea_
                If gdv_linea_.SelectedRowsCount > 0 Then
                    If barrio.Buscar(gdv_linea_.GetDataRow(gdv_linea_.GetSelectedRows(0))("idlinea")) Then
                        Dim ABM As New xtf_ABMlinea(obj_obra)
                        ABM.Modificar(barrio, Me, gdv_linea_.GetDataRow(gdv_linea_.GetSelectedRows(0)))
                        ABM.ControlarModificaciones(ABM.lac_general.Items)
                    End If
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub

    Private Sub cargarLinea_(ByVal idobra As Integer)
        dtt_linea_.Rows.Clear()
        Dim linea_ As New cls_linea_
        If linea_.CargarXidobra(idobra) Then
            For Each linea As cls_linea_ In linea_.Items
                AgregarItem(linea)
            Next
        End If
    End Sub

    Public Function AgregarItem(ByRef linea As cls_linea_) As DataRow
        Dim Row As DataRow = dtt_linea_.NewRow
        Row("idlinea") = linea.idlinea
        Row("Objeto") = linea
        Row("Nombre") = linea.nombre
        Row("Alcance") = linea.alcance
        If Not IsNothing(linea.sistema) Then
            Row("Sistema") = linea.sistema.ToString
        Else
            Row("Sistema") = ""
        End If
        If Not IsNothing(linea.subsistema) Then
            Row("Sub Sistema") = linea.subsistema.ToString
        Else
            Row("Sub Sistema") = ""
        End If
        If Not IsNothing(linea.material) Then
            Row("Material") = linea.material.ToString
        Else
            Row("Material") = ""
        End If
        dtt_linea_.Rows.Add(Row)
        Return Row
    End Function

    Public Sub ModificarItem(ByRef linea As cls_linea_, ByRef ulg_row As DataRow)
        ulg_row("idlinea") = linea.idlinea
        ulg_row("Objeto") = linea
        ulg_row("Nombre") = linea.nombre
        ulg_row("Alcance") = linea.alcance
        linea.sistema = Nothing
        If Not IsNothing(linea.sistema) Then
            ulg_row("Sistema") = linea.sistema.ToString
        Else
            ulg_row("Sistema") = ""
        End If
        linea.subsistema = Nothing
        If Not IsNothing(linea.subsistema) Then
            ulg_row("Sub Sistema") = linea.subsistema.ToString
        Else
            ulg_row("Sub Sistema") = ""
        End If
        linea.material = Nothing
        If Not IsNothing(linea.material) Then
            ulg_row("Material") = linea.material.ToString
        Else
            ulg_row("Material") = ""
        End If
    End Sub

    Private Sub gdv_linea__FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles gdv_linea_.FocusedRowChanged
        Dim view As DevExpress.XtraGrid.Views.Grid.GridView = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView)
        If view.SelectedRowsCount > 0 Then
            tsb_isometricoNuevo.Enabled = True
            Dim row As DataRow = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView).GetDataRow(view.GetSelectedRows(0))
            If Not IsNothing(row) Then
                tsb_lineaModificar.Enabled = True
                tsb_lineaEliminar.Enabled = True
                dtt_soldadura_.Rows.Clear()
                cargarisometrico_(row("idlinea"))
            Else
                tsb_lineaModificar.Enabled = False
                tsb_lineaEliminar.Enabled = False
                dtt_soldadura_.Rows.Clear()
                dtt_isometrico_.Rows.Clear()
            End If
        Else
            tsb_isometricoNuevo.Enabled = False
        End If
    End Sub

    Private Sub gdv_linea__DoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles gdv_linea_.DoubleClick
        Dim view As DevExpress.XtraGrid.Views.Grid.GridView = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView)
        Dim pt As Point = view.GridControl.PointToClient(Control.MousePosition)
        gdv_linea_DoRowDoubleClick(view, pt)
    End Sub

    Public Overridable Sub gdv_linea_DoRowDoubleClick(ByVal view As DevExpress.XtraGrid.Views.Grid.GridView, ByVal pt As Point)
        Dim info As DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo = view.CalcHitInfo(pt)
        If info.InRow OrElse info.InRowCell Then
            Dim colCaption As String
            If info.Column Is Nothing Then
                colCaption = "N/A"
            Else
                colCaption = info.Column.GetCaption()
            End If
            tsb_lineaModificar.PerformClick()
        End If
    End Sub
#End Region

#Region "Isometrico"
    Public Overridable Sub bbi_Nuevoisometrico_ItemClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsb_isometricoNuevo.Click
        If ComprobarPermiso(PERMISONuevoisometrico) Then
            If gdv_linea_.SelectedRowsCount > 0 Then
                Dim ABM As New xtf_ABMisometrico(obj_obra, gdv_linea_.GetDataRow(gdv_linea_.GetSelectedRows(0))("Objeto"))
                ABM.Nuevo(Me)
                ABM.ControlarModificaciones(ABM.lac_general.Items)
            End If
        End If
    End Sub

    Public Overridable Sub bbi_Modificarisometrico_ItemClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsb_isometricoModificar.Click
        If ComprobarPermiso(PERMISOModificarisometrico) Then
            Try
                Dim barrio As New cls_isometrico_
                If gdv_isometrico_.SelectedRowsCount > 0 Then
                    If barrio.Buscar(gdv_isometrico_.GetDataRow(gdv_isometrico_.GetSelectedRows(0))("idisometrico")) Then
                        Dim ABM As New xtf_ABMisometrico(obj_obra, gdv_linea_.GetDataRow(gdv_linea_.GetSelectedRows(0))("Objeto"))
                        ABM.Modificar(barrio, Me, gdv_isometrico_.GetDataRow(gdv_isometrico_.GetSelectedRows(0)))
                        ABM.ControlarModificaciones(ABM.lac_general.Items)
                    End If
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub

    Private Sub cargarisometrico_(ByVal idlinea As Integer)
        dtt_isometrico_.Rows.Clear()
        Dim isometrico_ As New cls_isometrico_
        If isometrico_.CargarXidlinea(idlinea) Then
            For Each isometrico As cls_isometrico_ In isometrico_.Items
                AgregarItem(isometrico)
            Next
        End If
    End Sub

    Public Function AgregarItem(ByRef isometrico As cls_isometrico_) As DataRow
        Dim Row As DataRow = dtt_isometrico_.NewRow
        Row("idisometrico") = isometrico.idisometrico
        Row("Objeto") = isometrico
        Row("Nombre") = isometrico.nombre
        Row("Código") = isometrico.codigo
        If Not IsNothing(isometrico.plano) Then
            Row("Plano") = isometrico.plano.ToString
        Else
            Row("Plano") = ""
        End If
        If Not IsNothing(isometrico.area) Then
            Row("Area") = isometrico.area.ToString
        Else
            Row("Area") = ""
        End If
        If Not IsNothing(isometrico.skid) Then
            Row("Skid") = isometrico.skid.ToString
        Else
            Row("Skid") = ""
        End If
        If Not IsNothing(isometrico.proveedor) Then
            Row("Contratista") = isometrico.proveedor.ToString
        Else
            Row("Contratista") = ""
        End If
        Row("Kilos campo") = isometrico.kiloscampo
        Row("Kilos taller") = isometrico.kilostaller
        Row("Observaciones") = isometrico.observaciones
        If Not IsNothing(isometrico.lineaopcional1) Then
            Row("Linea opcional 1") = isometrico.lineaopcional1.ToString
        Else
            Row("Linea opcional 1") = ""
        End If
        If Not IsNothing(isometrico.lineaopcional2) Then
            Row("Linea opcional 2") = isometrico.lineaopcional2.ToString
        Else
            Row("Linea opcional 2") = ""
        End If
        Row("Hojas") = isometrico.hoja
        Row("Hojas Total") = isometrico.hojatotal

        dtt_isometrico_.Rows.Add(Row)
        Return Row
    End Function

    Public Sub ModificarItem(ByRef isometrico As cls_isometrico_, ByRef ulg_row As DataRow)
        ulg_row("idisometrico") = isometrico.idisometrico
        ulg_row("Objeto") = isometrico
        ulg_row("Nombre") = isometrico.nombre
        ulg_row("Código") = isometrico.codigo
        isometrico.plano = Nothing
        If Not IsNothing(isometrico.plano) Then
            ulg_row("Plano") = isometrico.plano.ToString
        Else
            ulg_row("Plano") = ""
        End If
        isometrico.area = Nothing
        If Not IsNothing(isometrico.area) Then
            ulg_row("Area") = isometrico.area.ToString
        Else
            ulg_row("Area") = ""
        End If
        isometrico.skid = Nothing
        If Not IsNothing(isometrico.skid) Then
            ulg_row("Skid") = isometrico.skid.ToString
        Else
            ulg_row("Skid") = ""
        End If
        isometrico.proveedor = Nothing
        If Not IsNothing(isometrico.proveedor) Then
            ulg_row("Contratista") = isometrico.proveedor.ToString
        Else
            ulg_row("Contratista") = ""
        End If
        ulg_row("Kilos campo") = isometrico.kiloscampo
        ulg_row("Kilos taller") = isometrico.kilostaller
        ulg_row("Observaciones") = isometrico.observaciones
        If Not IsNothing(isometrico.lineaopcional1) Then
            ulg_row("Linea opcional 1") = isometrico.lineaopcional1.ToString
        Else
            ulg_row("Linea opcional 1") = ""
        End If
        If Not IsNothing(isometrico.lineaopcional2) Then
            ulg_row("Linea opcional 2") = isometrico.lineaopcional2.ToString
        Else
            ulg_row("Linea opcional 2") = ""
        End If
        ulg_row("Hojas") = isometrico.hoja
        ulg_row("Hojas Total") = isometrico.hojatotal
    End Sub


    Private Sub gdv_isometrico__FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles gdv_isometrico_.FocusedRowChanged
        Dim view As DevExpress.XtraGrid.Views.Grid.GridView = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView)
        If view.SelectedRowsCount > 0 Then
            tsb_soldaduraNuevo.Enabled = True
            Dim row As DataRow = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView).GetDataRow(view.GetSelectedRows(0))
            If Not IsNothing(row) Then
                tsb_isometricoModificar.Enabled = True
                tsb_isometricoEliminar.Enabled = True
                cargarsoldadura_(row("idisometrico"), cls_soldadura_.enu_tipo.piping)
            Else
                dtt_soldadura_.Rows.Clear()
                tsb_isometricoModificar.Enabled = False
                tsb_isometricoEliminar.Enabled = False
            End If
        Else
            tsb_soldaduraNuevo.Enabled = False
            tsb_isometricoModificar.Enabled = False
            tsb_isometricoEliminar.Enabled = False
        End If
    End Sub

    Private Sub gdv_isometrico__DoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles gdv_isometrico_.DoubleClick
        Dim view As DevExpress.XtraGrid.Views.Grid.GridView = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView)
        Dim pt As Point = view.GridControl.PointToClient(Control.MousePosition)
        gdv_isometrico_DoRowDoubleClick(view, pt)
    End Sub

    Public Overridable Sub gdv_isometrico_DoRowDoubleClick(ByVal view As DevExpress.XtraGrid.Views.Grid.GridView, ByVal pt As Point)
        Dim info As DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo = view.CalcHitInfo(pt)
        If info.InRow OrElse info.InRowCell Then
            Dim colCaption As String
            If info.Column Is Nothing Then
                colCaption = "N/A"
            Else
                colCaption = info.Column.GetCaption()
            End If
            tsb_isometricoModificar.PerformClick()
        End If
    End Sub
#End Region

#Region "Soldadura"
    Public Overridable Sub bbi_Nuevosoldadura_ItemClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsb_soldaduraNuevo.Click
        If ComprobarPermiso(PERMISONuevosoldadura) Then
            If gdv_isometrico_.SelectedRowsCount > 0 Or opt_soldaduratipo.SelectedIndex <> cls_soldadura_.enu_tipo.piping Then
                Dim linea As cls_linea_
                Dim isometrico As cls_isometrico_

                If opt_soldaduratipo.SelectedIndex = cls_soldadura_.enu_tipo.piping Then
                    linea = gdv_linea_.GetDataRow(gdv_linea_.GetSelectedRows(0))("Objeto")
                    isometrico = gdv_isometrico_.GetDataRow(gdv_isometrico_.GetSelectedRows(0))("Objeto")
                Else
                    linea = New cls_linea_
                    isometrico = New cls_isometrico_
                End If

                Dim ABM As New xtf_ABMsoldadura(obj_obra, linea, isometrico, opt_soldaduratipo.SelectedIndex)
                ABM.Nuevo(Me)
                ABM.ControlarModificaciones(ABM.lac_general.Items)
            End If
        End If
    End Sub

    Public Overridable Sub bbi_Modificarsoldadura_ItemClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tsb_soldaduraModificar.Click
        If ComprobarPermiso(PERMISOModificarsoldadura) Then
            Try
                Dim barrio As New cls_soldadura_
                If gdv_soldadura_.SelectedRowsCount > 0 Or opt_soldaduratipo.SelectedIndex <> cls_soldadura_.enu_tipo.piping Then
                    If barrio.Buscar(gdv_soldadura_.GetDataRow(gdv_soldadura_.GetSelectedRows(0))("idsoldadura")) Then
                        Dim linea As cls_linea_
                        Dim isometrico As cls_isometrico_

                        If opt_soldaduratipo.SelectedIndex = cls_soldadura_.enu_tipo.piping Then
                            linea = gdv_linea_.GetDataRow(gdv_linea_.GetSelectedRows(0))("Objeto")
                            isometrico = gdv_isometrico_.GetDataRow(gdv_isometrico_.GetSelectedRows(0))("Objeto")
                        Else
                            linea = New cls_linea_
                            isometrico = New cls_isometrico_
                        End If

                        Dim ABM As New xtf_ABMsoldadura(obj_obra, linea, isometrico, opt_soldaduratipo.SelectedIndex)
                        ABM.Modificar(barrio, Me, gdv_soldadura_.GetDataRow(gdv_soldadura_.GetSelectedRows(0)))
                        ABM.ControlarModificaciones(ABM.lac_general.Items)
                    End If
                End If
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        End If
    End Sub

    Private Sub cargarsoldadura_(ByVal idisometrico As Integer, ByVal tipo As cls_soldadura_.enu_tipo)
        dtt_soldadura_.Rows.Clear()
        Dim soldadura_ As New cls_soldadura_
        If tipo = cls_soldadura_.enu_tipo.piping Then
            If soldadura_.CargarXidisometrico(idisometrico) Then
                For Each soldadura As cls_soldadura_ In soldadura_.Items
                    AgregarItem(soldadura)
                Next
            End If
        Else
            If soldadura_.CargarXidobraXtipo(obj_obra.idcentrocostoorden, opt_soldaduratipo.SelectedIndex) Then
                For Each soldadura As cls_soldadura_ In soldadura_.Items
                    AgregarItem(soldadura)
                Next
            End If
        End If
        
    End Sub

    Public Function AgregarItem(ByRef soldadura As cls_soldadura_) As DataRow
        Dim Row As DataRow = dtt_soldadura_.NewRow
        Row("idsoldadura") = soldadura.idsoldadura
        Row("Objeto") = soldadura
        Row("Tipo") = EnumDescription(soldadura.tipo)
        Row("Código") = soldadura.codigo
        Row("Diámetro Nom.") = soldadura.diametro
        Row("Diámetro") = soldadura.diametro2
        Row("Schedule") = soldadura.schedule
        Row("Espesor") = soldadura.espesor
        If Not IsNothing(soldadura.soldaduratipo) Then
            Row("Tipo de Soldadura") = soldadura.soldaduratipo.ToString
        Else
            Row("Tipo de Soldadura") = ""
        End If
        Row("Se hace en") = EnumDescription(soldadura.fabricadoen)
        Row("Tipo Nuevo") = EnumDescription(soldadura.tiponuevo)

        dtt_soldadura_.Rows.Add(Row)
        Return Row
    End Function

    Public Sub ModificarItem(ByRef soldadura As cls_soldadura_, ByRef ulg_row As DataRow)
        ulg_row("idsoldadura") = soldadura.idsoldadura
        ulg_row("Objeto") = soldadura
        ulg_row("Tipo") = EnumDescription(soldadura.tipo)
        ulg_row("Código") = soldadura.codigo
        ulg_row("Diámetro Nom.") = soldadura.diametro
        ulg_row("Diámetro") = soldadura.diametro2
        ulg_row("Schedule") = soldadura.schedule
        ulg_row("Espesor") = soldadura.espesor
        soldadura.soldaduratipo = Nothing
        If Not IsNothing(soldadura.soldaduratipo) Then
            ulg_row("Tipo de Soldadura") = soldadura.soldaduratipo.ToString
        Else
            ulg_row("Tipo de Soldadura") = ""
        End If
        ulg_row("Se hace en") = EnumDescription(soldadura.fabricadoen)
        ulg_row("Tipo Nuevo") = EnumDescription(soldadura.tiponuevo)
    End Sub

    Private Sub gdv_soldadura__DoubleClick(ByVal sender As Object, ByVal e As EventArgs) Handles gdv_soldadura_.DoubleClick
        Dim view As DevExpress.XtraGrid.Views.Grid.GridView = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView)
        Dim pt As Point = view.GridControl.PointToClient(Control.MousePosition)
        gdv_soldadura_DoRowDoubleClick(view, pt)
    End Sub

    Public Overridable Sub gdv_soldadura_DoRowDoubleClick(ByVal view As DevExpress.XtraGrid.Views.Grid.GridView, ByVal pt As Point)
        Dim info As DevExpress.XtraGrid.Views.Grid.ViewInfo.GridHitInfo = view.CalcHitInfo(pt)
        If info.InRow OrElse info.InRowCell Then
            Dim colCaption As String
            If info.Column Is Nothing Then
                colCaption = "N/A"
            Else
                colCaption = info.Column.GetCaption()
            End If
            tsb_soldaduraModificar.PerformClick()
        End If
    End Sub

    Private Sub gdv_soldadura__FocusedRowChanged(ByVal sender As Object, ByVal e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles gdv_soldadura_.FocusedRowChanged
        Dim view As DevExpress.XtraGrid.Views.Grid.GridView = CType(sender, DevExpress.XtraGrid.Views.Grid.GridView)
        If view.SelectedRowsCount > 0 Then
            tsb_soldaduraModificar.Enabled = True
            tsb_soldaduraEliminar.Enabled = True
            tsb_soldaduraCopiar.Enabled = True
            Dim soldadura As cls_soldadura_ = gdv_soldadura_.GetDataRow(gdv_soldadura_.GetSelectedRows(0))("Objeto")
            If soldadura.tiponuevo = cls_soldadura_.enu_tiponuevo.nueva Then
                tsb_soldaduraCopiar.Enabled = True
            Else
                tsb_soldaduraCopiar.Enabled = False
            End If
        Else
            tsb_soldaduraCopiar.Enabled = False
            tsb_soldaduraModificar.Enabled = False
            tsb_soldaduraEliminar.Enabled = False
            tsb_soldaduraCopiar.Enabled = False
        End If
    End Sub

    Private Sub tsb_soldaduraCopiar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsb_soldaduraCopiar.Click
        Dim barrio As New cls_soldadura_
        If gdv_soldadura_.SelectedRowsCount > 0 Then
            If barrio.Buscar(gdv_soldadura_.GetDataRow(gdv_soldadura_.GetSelectedRows(0))("idsoldadura")) Then
                Dim ABMcopiar As New xtf_COPIARsoldadura(barrio, Me)
                ABMcopiar.ShowDialog()
            End If
        End If

    End Sub
#End Region


 
    Private Sub btn_Cerrar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Cerrar.Click
        Me.Close()
    End Sub

    Private Sub gdc_linea__Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles gdc_linea_.Click

    End Sub

  
    Private Sub xtf_ListadoBase_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        guardar_config_usuariocolumna_(gdv_isometrico_)
        guardar_config_usuariocolumna_(gdv_linea_)
        guardar_config_usuariocolumna_(gdv_soldadura_)
    End Sub

    Private Sub guardar_config_usuariocolumna_(ByRef prm_GridView As DevExpress.XtraGrid.Views.Grid.GridView)
        Dim obj_config_usuariocolumna_ As New cls_config_usuariocolumna_
        If obj_config_usuariocolumna_.Buscarxidusuarioxmodulo(UsuarioLOG.idusuario, Me.Name & prm_GridView.Name) Then
            obj_config_usuariocolumna_.xml = GetLayoutData(prm_GridView)
            obj_config_usuariocolumna_.Modificar()
        Else
            obj_config_usuariocolumna_.xml = GetLayoutData(prm_GridView)
            obj_config_usuariocolumna_.idusuario = UsuarioLOG.idusuario
            obj_config_usuariocolumna_.modulo = Me.Name & prm_GridView.Name
            obj_config_usuariocolumna_.Nuevo()
        End If
    End Sub

    Private Function GetLayoutData(ByRef prm_GridView As DevExpress.XtraGrid.Views.Grid.GridView) As Byte()
        Dim stream As New System.IO.MemoryStream()
        prm_GridView.SaveLayoutToStream(stream)
        Return stream.GetBuffer()
    End Function

    Private Sub SetLayoutData(ByRef prm_GridView As DevExpress.XtraGrid.Views.Grid.GridView, ByVal data As Byte())
        If data Is Nothing OrElse data.Length = 0 Then
            Return
        End If
        Dim stream As New System.IO.MemoryStream(data)
        Try
            prm_GridView.RestoreLayoutFromStream(stream)
            Dim config_parametro As New cls_config_parametro_
            prm_GridView.OptionsView.ColumnAutoWidth = config_parametro.Buscar("grillaAutoWidth").valor
        Catch ex As Exception
            Throw New Exception("Wrong data format", ex)
        End Try
    End Sub

    Public Sub FiltrarColumnas(ByRef prm_GridView As DevExpress.XtraGrid.Views.Grid.GridView)
        Dim int_IDUsuario As Integer = UsuarioLOG.idusuario
        Dim obj_config_usuariocolumna_ As New cls_config_usuariocolumna_
        prm_GridView.BeginUpdate()
        If obj_config_usuariocolumna_.Buscarxidusuarioxmodulo(int_IDUsuario, Me.Name & prm_GridView.Name) Then
            SetLayoutData(prm_GridView, obj_config_usuariocolumna_.xml)
        End If
        prm_GridView.EndUpdate()
    End Sub

    
    Private Sub opt_soldaduratipo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles opt_soldaduratipo.SelectedIndexChanged
        If opt_soldaduratipo.SelectedIndex = cls_soldadura_.enu_tipo.piping Then
            lac_general.BeginUpdate()
            lcg_isometrico_.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always
            lcg_linea_.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always
            tsb_soldaduraNuevo.Enabled = False
            cargarLinea_(obj_obra.idcentrocostoorden)
            lac_general.EndUpdate()
        Else
            lac_general.BeginUpdate()
            lcg_isometrico_.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never
            lcg_linea_.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never
            tsb_soldaduraNuevo.Enabled = True
            cargarsoldadura_(obj_obra.idcentrocostoorden, opt_soldaduratipo.SelectedIndex)
            lac_general.EndUpdate()
        End If
    End Sub
End Class